package leetcode;

import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

public class MyCalendarTwo {

    TreeMap<int[], Integer> map = new TreeMap<>(new Comparator<int[]>() {
        @Override
        public int compare(int[] o1, int[] o2) {
//            if (o1[0] >= o2[1]) return 1;
//            else if (o1[1] <= o2[0]) return -1;
//            else return 0;
            return o1[0] - o2[0];
        }
    });

    public MyCalendarTwo() {

    }

    public boolean book(int startTime, int endTime) {

        if (map.isEmpty()) {
            map.put(new int[]{startTime, endTime}, 1);
            return true;
        }
        int[] right = map.floorKey(new int[]{endTime, 0}); //右边是否有重叠
        int[] left = map.ceilingKey(new int[]{startTime, 0}); //左边是否有重叠
//        if (right[0])

        return false;
    }

    public static void main(String[] args) {
        TreeMap<int[], Integer> map = new TreeMap<>(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
//            if (o1[0] >= o2[1]) return 1;
//            else if (o1[1] <= o2[0]) return -1;
//            else return 0;
                return o1[0] - o2[0];
            }
        });
        System.out.println(map.put(new int[]{0, 1}, 1));
        System.out.println(map.put(new int[]{0, 2}, 1));
        System.out.println();
    }


}
